You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
56 lines
1.9 KiB
56 lines
1.9 KiB
import { dbGlobal } from "drizzle-pkg/lib/db";
|
|
import { users } from "drizzle-pkg/lib/schema/auth";
|
|
import { and, eq } from "drizzle-orm";
|
|
import { listPublicPostsBySlug } from "#server/service/posts";
|
|
import { listPublicTimelineBySlug } from "#server/service/timeline";
|
|
import { listPublicRssItemsBySlug } from "#server/service/rss";
|
|
import { parseSocialLinksJson } from "#server/service/profile";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const publicSlug = event.context.params?.publicSlug;
|
|
if (!publicSlug || typeof publicSlug !== "string") {
|
|
throw createError({ statusCode: 400, statusMessage: "无效主页" });
|
|
}
|
|
|
|
const [owner] = await dbGlobal
|
|
.select()
|
|
.from(users)
|
|
.where(and(eq(users.publicSlug, publicSlug), eq(users.status, "active")))
|
|
.limit(1);
|
|
|
|
if (!owner) {
|
|
throw createError({ statusCode: 404, statusMessage: "未找到" });
|
|
}
|
|
|
|
const links = parseSocialLinksJson(owner.socialLinksJson).filter((l) => l.visibility === "public");
|
|
|
|
const payload: {
|
|
user: {
|
|
publicSlug: string | null;
|
|
nickname: string | null;
|
|
avatar: string | null;
|
|
};
|
|
bio: { markdown: string | null } | null;
|
|
links: typeof links;
|
|
posts: Awaited<ReturnType<typeof listPublicPostsBySlug>>;
|
|
timeline: Awaited<ReturnType<typeof listPublicTimelineBySlug>>;
|
|
rssItems: Awaited<ReturnType<typeof listPublicRssItemsBySlug>>;
|
|
} = {
|
|
user: {
|
|
publicSlug: owner.publicSlug,
|
|
nickname: owner.nickname,
|
|
avatar: owner.avatarVisibility === "public" ? owner.avatar : null,
|
|
},
|
|
bio: null,
|
|
links,
|
|
posts: await listPublicPostsBySlug(publicSlug),
|
|
timeline: await listPublicTimelineBySlug(publicSlug),
|
|
rssItems: await listPublicRssItemsBySlug(publicSlug),
|
|
};
|
|
|
|
if (owner.bioVisibility === "public" && owner.bioMarkdown) {
|
|
payload.bio = { markdown: owner.bioMarkdown };
|
|
}
|
|
|
|
return R.success(payload);
|
|
});
|
|
|